{% extends base %}

{% block head %}
<script type="text/javascript" src="/static/lib/utf.js"></script>
{% end %}
{% block body %}

<div class="card">
    {% set title = "Base64编解码" %}
    {% include "tools/base_title.html" %}
</div>

<div class="card">
    <div class="col-md-6">
        <label>Input</label>
        <textarea id="input" class="col-md-12" rows=10></textarea>
    </div>

    <div class="col-md-6">
        <label>Output</label>
        <textarea id="output" class="col-md-12" rows=10></textarea>
    </div>

    <div class="col-md-12">
        <button onclick="base64Encode()">Encode</button>
        <button onclick="base64Decode()">Decode</button>
    </div>
</div>

<script>
function base64Encode() {
    var bytes = utf16to8($("#input").val());
    $("#output").val(btoa(bytes));
}

function base64Decode() {
    var chars = atob($("#input").val());
    var str = utf8to16(chars);
    $("#output").val(str);
}
</script>
{% end %}